'''
Created on 2011-3-2
@author: bnw
'''

from stocktable import stocklist
import cx_Oracle
import os

if __name__ == '__main__':
    os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.ZHS16GBK'

    connection = cx_Oracle.connect('istock_user', 'istock_user', 'localhost:1521/orcl')
    cursor = connection.cursor()

    for i in range(0, len(stocklist)):
        stockid = stocklist[i][0]
        print stockid
        stockname = stocklist[i][1]
        stockname = stockname.decode('utf8')
        stockname = stockname.encode('gbk')
	sql = ("insert into STOCK_INFO (id, stock_id, stock_name) values (SEQUENCE_STOCK_INFO.NEXTVAL,"+"'"+stockid+"'," + "'"+stockname+"')")
	cursor.execute(sql)
##    cursor.execute("select * from STOCK_INFO where id = 11")
##    rows = cursor.fetchall()
##    print rows[0][2]
    connection.commit()
    cursor.close()
    connection.close()
    
    

    
